package com.fenghongzhang.a18103.mvp.presenter;

import com.fenghongzhang.a18103.entity.Food;
import com.fenghongzhang.a18103.mvp.contract.FoodContract;
import com.fenghongzhang.lib.mvp.presenter.BasePresenter;
import com.google.gson.Gson;

import java.io.IOException;
import java.util.List;

import javax.inject.Inject;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class FoodPresenter extends BasePresenter<FoodContract.IFoodModel,FoodContract.IFoodView> {

    private static final String TAG = "FoodPresenter";
    @Inject
    public FoodPresenter(FoodContract.IFoodModel mModel, FoodContract.IFoodView mView) {
        super(mModel, mView);
    }

    public void getData(){
        //调用model层的数据方法
        mModel.getFoodData(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String string = response.body().string();
                Food food = new Gson().fromJson(string, Food.class);
                List<Food.DataBean> data = food.getData();
                //把值给了view
                mView.initAdapter(data);

            }
        });
    }

}
